<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <!-- ECharts单文件引入 -->
    <script src="js/lib/require.min.js"></script>
    <script src="js/lib/jquery-1.11.2.min.js"></script>
    <script src="js/lib/jSouper.min.js"></script>
    <script type="text/javascript">
        // 路径配置
        require.config({
            paths: {
                echarts: 'js/lib/echarts-2.2.7'
            }
        });
        define("jQuery",function () {
            return $
        });
    </script>
    <title>钓鱼呵呵</title>
</head>
<body>
    <div id="jSouperApp">
        <h1>{{typeMap[type]}}</h1>
        <div>
            <input type="radio" value="mju" checked="{{type}}" bind-input="{{'type'}}">{{typeMap.mju}}
        </div>
        <div>
            <input type="radio" value="minyun" checked="{{type}}" bind-input="{{'type'}}">{{typeMap.minyun}}
        </div>
        <div>
            用户名：<input type="text" value="{{login_info.username}}" bind-input="{{'login_info.username'}}">
        </div>
        <div>
            密码：<input type="text" value="{{login_info.password}}" bind-input="{{'login_info.password'}}">
        </div>
        <div>
            验证码：<input type="text" value="{{login_info.captcha}}" bind-input="{{'login_info.captcha'}}">
            <img bind-src="{{server_url}}fishing/init/{{type}}/{{id}}" alt="验证码" event-click="{{'refresh_id'}}">
        </div>
        <button event-click="{{'login_and_get_userinfo'}}">提交</button>
        {{#if user_info}}
            <h2>用户信息：</h2>
            <xmp>
            {{window.JSON.stringify(user_info,null,4)}}
            </xmp>
        {{/if}}
    </div>
    <script>  
    var _tasks = [
        $.getScript("js/lib/tools.js")
    ];
    var server_url = location.host.indexOf("dev.dotnar.com") == -1 ? "http://api.dotnar.com/" : "http://dev.dotnar.com:3000/";
    $.when.apply($, _tasks).then(function() {
        jSouper.app({
            Id: "jSouperApp",
            Data: {
                // title: "闽运用户数据代理抓取",
                id: Math.random().toString(16).substr(2),
                server_url: server_url,
                typeMap: {
                    minyun: "闽运用户登录",
                    mju: "闽江学院教务管理学生登录"
                },
                type:"mju"
            }
        });
        App.set("login_and_get_userinfo", function() {
            require(["coAjax"], function(coAjax) {
                var _id = App.get("id")
                var _type = App.get("type")
                coAjax.post(server_url + "fishing/login/"+_type+"/" + _id, App.get("login_info"), function() {
                    alert("用户登录成功")
                    coAjax.get(server_url + "fishing/user_info/"+_type+"/" + _id, function(res) {
                        alert("用户信息获取成功");
                        App.set("user_info", res.result);
                        App.get("refresh_id")()
                    });
                }, function(c, x, msg) {
                    App.get("refresh_id")()
                    alert(msg);
                });
            })
        });
        App.set("refresh_id", function() {
            App.set("id", Math.random().toString(16).substr(2));
        })
    });
    </script>
</body>